﻿//
// Copyright 2024 Exhunter Technology Co.Ltd2.
//

using System;

namespace X18.Framework.Core.Hash
{
    /// <summary>
    /// Sha3(256)算法
    /// </summary>
    public static class Sha1
    {
        public static string ComputeHashToString(string data)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
            byte[] buffer = ComputeHashToBytes(bytes);
            string result = BitConverter.ToString(buffer);
            return result;
        }

        public static string ComputeHashToString(byte[] data)
        {
            byte[] buffer = ComputeHashToBytes(data);
            string result = BitConverter.ToString(buffer);
            return result;
        }

        public static byte[] ComputeHashToBytes(string data)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
            byte[] result = ComputeHashToBytes(bytes);
            return result;
        }

        public static byte[] ComputeHashToBytes(byte[] data)
        {
            using (var sha = System.Security.Cryptography.SHA1.Create())
            {
                return sha.ComputeHash(data);
            }
        }
    }
}
